﻿using System.Collections;
using TMPro;
using UnityEngine;
using XFramework;
using XFramework.UI;

public class StoryPanel : PanelBase
{
    private TMP_Text m_StoryText;

    public override void Reg()
    {
        m_StoryText = (this["StoryText"] as GUTMPText).text;
    }

    public override void OnUpdate()
    {
        if (Input.GetKeyDown(KeyCode.J))
        {
            PrientText("jkghlafdskjhlfiugaseiuyfulaow;dflghjasdo;lifhaslidfhasdklfgialsfyoiewbfknkz,jxcvhljksdaf;lodhlksaflhkasddflhiaskdhjfaklujsdfgkulasdkljfgasufklasdhglkjfkjgasdf", 0.05f);
        }
    }

    public void PrientText(string content, float perChar)
    {
        MonoEvent.Instance.StartCoroutine(Prient(content, perChar));
    }

    private IEnumerator Prient(string content, float perChar)
    {
        m_StoryText.text = "";
        for (int i = 0; i < content.Length; i++)
        {
            yield return perChar;
            m_StoryText.text += content[i];
        }
    }
}
